home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / smphone / ph_iouser.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-11  |  6.2 KB  |  229 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3. #include "ph.h"
  4. /*
  5.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  6.  *     
  7.  *
  8.  *     Copyright (C) 1979,1980,1981  University of Delaware
  9.  *     
  10.  *     Department of Electrical Engineering
  11.  *     University of Delaware
  12.  *     Newark, Delaware  19711
  13.  *
  14.  *     Phone:  (302) 738-1163
  15.  *     
  16.  *     
  17.  *     This program module was developed as part of the University
  18.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  19.  *     
  20.  *     Acquisition, use, and distribution of this module and its listings
  21.  *     are subject restricted to the terms of a license agreement.
  22.  *     Documents describing systems using this module must cite its source.
  23.  *
  24.  *     The above statements must be retained with all copies of this
  25.  *     program and may not be removed without the consent of the
  26.  *     University of Delaware.
  27.  *     
  28.  *
  29.  *     version  -1    David H. Crocker    March   1979
  30.  *     version   0    David H. Crocker    April   1980
  31.  *     version  v7    David H. Crocker    May     1981
  32.  *     version   1    David H. Crocker    October 1981
  33.  *
  34.  */
  35. /*#define RUNALON   */
  36.  
  37. /*                  Handle telephone-based i/o                          */
  38.  
  39. /*  Jul, 80 Dave Crocker    remove ph_d_started setting from ph_init    */
  40. /*  Feb, 82 D. Long        improved ll_log hdr field for wider chan name */
  41. /*  Mar, 84 D. Long         added use of per-channel phone transcript */
  42.  
  43. #include "d_returns.h"
  44. #include "ch.h"
  45. #include "phs.h"
  46.  
  47. extern time_t time ();
  48. extern Chan *curchan;
  49. extern struct ll_struct   *logptr,
  50.                ph_log;
  51. extern char *logdfldir;
  52. extern char *tbldfldir;
  53. extern char *supportaddr;
  54. LOCVAR time_t  starttime;        /* time interaction started           */
  55.  
  56. extern char *def_trn;             /* straight transcript of char i/o    */
  57. extern struct ps_rstruct ps_rp;
  58.  
  59. LOCVAR char ph_d_started;         /* called dial package yet?           */
  60. LOCVAR char smtp_sender;          /* are we in smtp-sender mode?        */
  61. LOCVAR char *ph_trn;          /* filled-out version of phone trn file */
  62. LOCVAR char *ph_script;           /* filled-out version of dialing script */
  63.  
  64. /*  ********  (ph_)  PHONE MAIL MASTER INIT/END SUB-MODULE  ********** */
  65.  
  66. ph_init ()              /* call remote, to do mail            */
  67. {
  68.     extern char *dupfpath ();
  69.     short     retval;
  70.     char linebuf[LINESIZE];
  71.  
  72. #ifdef DEBUG
  73.     ll_log (logptr, LLOGBTR, "ph_init ()");
  74. #endif
  75.     if (ph_d_started)             /* tried before?                      */
  76.     {
  77.     ph_end (NOTOK);           /* make sure old channel gone         */
  78.     sleep (10);               /* just for the hell of it            */
  79.     ll_log (logptr, LLOGTMP, "[ REDIAL ]");
  80.     printx ("re-");
  81.     }
  82.     else
  83.     {
  84. /*    ll_hdinit (&ph_log, " D");   /* header unique for send             */
  85.     ll_hdinit (&ph_log, logptr -> ll_hdr);   /* init header for send    */
  86. /*    ph_log.ll_hdr[0] = logptr -> ll_hdr[0];  */
  87.     ph_log.ll_hdr[0] = 'D';  /* unique letter for send */
  88.     ph_log.ll_file = dupfpath (ph_log.ll_file, logdfldir);
  89.                    /* fill-out path to log files        */
  90.  
  91.     ph_script = dupfpath (curchan -> ch_script, tbldfldir);
  92.  
  93.     if (curchan -> ch_trans == (char *) DEFTRANS)
  94.         ph_trn = dupfpath (def_trn, logdfldir);
  95.     else
  96.         ph_trn = dupfpath (curchan -> ch_trans, logdfldir);
  97.  
  98.     ll_log (logptr, LLOGGEN, "dialing");
  99.     }
  100.     printx ("dialing... ");
  101.     fflush (stdout);
  102. #ifndef RUNALON
  103.     ph_d_started = TRUE;
  104.     phs_note (curchan, PHS_CNSTRT);
  105.                   /* note WHICH phone channel           */
  106.     if ((retval = d_masconn (ph_script, &ph_log, TRUE, ph_trn,
  107.                 (ph_log.ll_level >= LLOGBTR) ? TRUE : FALSE))
  108.         < D_OK)
  109.     {
  110.     printx ("couldn't connect.\n");
  111.     retval = ph_d2rpval (retval);
  112.                   /* map return to rp.h value           */
  113.     ll_log (logptr, LLOGTMP,
  114.             "unable to connect (%s)", rp_valstr (retval));
  115.     return (retval);
  116.     }
  117. #endif
  118.  
  119.     printx ("\007connected.\n");
  120.     fflush (stdout);
  121.     phs_note (curchan, PHS_CNGOT);
  122.  
  123.     if (rp_isbad (ps_irdrply ()) ||
  124.         rp_isbad (ps_rp.sm_rval != 220))
  125.     {
  126.     ll_log (logptr, LLOGFAT, "no greeting");
  127.     return (RP_NO);
  128.     }
  129.  
  130.     if (curchan -> ch_confstr)
  131.     sprintf (linebuf, "HELO %s", curchan -> ch_confstr);
  132.     else
  133.     sprintf (linebuf, "HELO %s.%s", curchan -> ch_lname,
  134.                     curchan -> ch_ldomain);
  135.     if (rp_isbad (ps_cmd( linebuf )) || ps_rp.sm_rval != 250 ) {
  136.     ll_log(logptr, LLOGFAT, "bad response to HELO");
  137.     return (RP_NO);
  138.     }
  139.  
  140.     smtp_sender = TRUE;
  141.  
  142.     return (RP_OK);
  143. }
  144. /* */
  145.  
  146. ph_end (type)                     /* done with mail process             */
  147. short     type;                     /* clean / dirty ending               */
  148. {
  149.  
  150. #ifdef DEBUG
  151.     ll_log (logptr, LLOGBTR, "ph_end ()");
  152. #endif
  153.  
  154.     if (ph_d_started)             /* is phone channel even active?      */
  155.     {
  156.     ph_d_started = FALSE;
  157.  
  158.     /* if smtp_sender is set and we're ending OK, need to do QUIT first */
  159.     /* if smtp_sender is not set and we're ending OK, skip the QUIT */
  160.     /* either way, an OK ending deserves a script completion */
  161.     if ( (type == OK) &&
  162.          ( (!smtp_sender) || (smtp_sender && rp_isgood(ps_cmd("QUIT"))) ) )
  163.     {
  164.         d_masdrop (0, TRUE);
  165.         phs_end(curchan, RP_OK);
  166.     }
  167.     else
  168.     {
  169.             d_masdrop (0, 0);     /* don't finish the script            */
  170.             phs_end(curchan, RP_NO);
  171.     }
  172.     return;
  173.     }
  174. }
  175. /* */
  176.  
  177. ph_sbinit ()                      /* ready to submit to remote site     */
  178. {
  179. #ifdef DEBUG
  180.     ll_log (logptr, LLOGBTR, "ph_sbinit ()");
  181. #endif
  182.  
  183.     return (RP_OK);
  184. }
  185.  
  186. ph_sbend ()                       /* done with submission               */
  187. {
  188. #ifdef DEBUG
  189.     ll_log (logptr, LLOGBTR, "ph_sbend ()");
  190. #endif
  191.  
  192.     return (RP_OK);
  193. }
  194. /* */
  195.  
  196. ph_pkinit ()                      /* initialize remote pickup            */
  197. {
  198.     char replybuf[128];
  199.     short retval;
  200.  
  201. #ifdef DEBUG
  202.     ll_log (logptr, LLOGPTR, "ph_pkinit ()");
  203. #endif
  204.  
  205.     if (rp_isbad (ps_cmd( "TURN" )) || ps_rp.sm_rval != 250 ) {
  206.     ll_log (logptr, LLOGFAT, "can't pickup");
  207.     return (RP_NO);
  208.     }
  209.  
  210.     /* say we're listening */
  211.     sprintf (replybuf, "220 Server SMTP (Complaints/bugs to:  %s)",
  212.                supportaddr);
  213.     if (rp_isbad (retval = ph_wrec (replybuf, strlen(replybuf)))) 
  214.     return (retval);
  215.     
  216.     smtp_sender = FALSE;
  217.  
  218.     return (RP_OK);
  219. }
  220.  
  221. ph_pkend ()                       /* done with pickup                   */
  222. {
  223. #ifdef DEBUG
  224.     ll_log (logptr, LLOGBTR, "ph_pkend ()");
  225. #endif
  226.  
  227.     return (RP_OK);
  228. }
  229.